package com.piece.blog.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.piece.blog.api.support.BlogAuthor;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
@Entity
@NoArgsConstructor
@Table(name = "blog_article_comment")
@ApiModel(value = "文章评论表:blog_article_comment")
public class ArticleComment implements Serializable {

    @Id
    @Column(name = "comment_id", length = 11)
    @ApiModelProperty(value = "主键")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long commentId;

    @Column(name = "comment_user_id")
    @ApiModelProperty(value = "评论人")
    private Long commentUserId;

    @Column(name = "target_user_id")
    @ApiModelProperty(value = "被评论人")
    private Long targetUserId;

    @Column(name = "article_id")
    @ApiModelProperty(value = "文章ID")
    private Long articleId;

    @Column(name = "content")
    @ApiModelProperty(value = "内容")
    private String content;

    @Column(name = "parent_id", length = 11)
    @ApiModelProperty(value = "父评论ID")
    private Long parentId;

    @Column(name = "status")
    @ApiModelProperty(value = "状态", notes = "0=正常, 1=删除")
    private String status;

    @Column(name = "create_by")
    @ApiModelProperty(value = "创建人ID")
    private Long createBy;

    @Column(name = "create_time")
    @ApiModelProperty(value = "创建时间")
    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private Date createTime;

    @Transient
    private Long id;

    @Transient
    @ApiModelProperty(value = "评论人")
    private BlogAuthor commentUser;

    @Transient
    @ApiModelProperty(value = "被评论人")
    private BlogAuthor targetUser;

    @Transient
    @ApiModelProperty(value = "子评论列表")
    private List<ArticleComment> childrenList = new ArrayList<>();
}
